package thread.lock;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.ReentrantLock;

public class ConcreteThread implements Runnable {

	private static final ReentrantLock locks = new ReentrantLock();
	private String name;

	ConcreteThread(String name) {
		this.name = name;
	}

	public void run() {
		try {
			locks.lock();
			for (int cnt = 0; cnt < 5; cnt++) {
				System.out.println(name + " " + cnt);
				Thread.sleep(1000);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			locks.unlock();
		}
	}

	public static void main(String[] args) throws Exception {
		ExecutorService executor = Executors.newScheduledThreadPool(10);
		executor.execute(new ConcreteThread("A"));
		executor.execute(new ConcreteThread("B"));
	}

}
